import time
from selenium import webdriver

class test_data():
    def __init__(self):
        self.driver=webdriver.Firefox()

    def open_p(self):
        self.driver.get("http://localhost:8088/agileone")

    def login(self,username,password):
        self.driver.find_element_by_id("username").clear()
        self.driver.find_element_by_id("username").send_keys(username)
        self.driver.find_element_by_id("password").clear()
        self.driver.find_element_by_id("password").send_keys(password)
        self.driver.find_element_by_id("login").click()

    def test_login(self,username,password,expect):
        self.login(username,password)
        time.sleep(3)
        actual=self.driver.find_element_by_id('msg').text
        print(actual)
        time.sleep(3)
        print(actual)
        if expect in actual:
            print("ok")
        else:
            print('ko')

    def close_p(self):
        self.driver.quit()
if __name__ == '__main__':

    test=test_data()
    test.open_p()
     # test.test_login("admin","","出错啦: 密码输入错误 ...")
     # test.test_login("admin123", "admin", "出错啦: 找不到该用户名 ...")

    with open("data.txt") as f:
        res=f.readlines()
        # print(res)

        for line in res:
            # print(line)
            # print(line.strip())
            # print(line.strip().split(","))
                print(line.strip().split(",")[0])
                username=line.strip().split(",")[0]
                password=line.strip().split(",")[1]
                expect=line.strip().split(",")[2]
                test.test_login(username,password,expect)
        # for line in f.readlines():
        #    print(line)
        #     test.close_p()




